import java.util.Objects;

class Person{
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void print(){
        System.out.println(name + " " + age);
    }

    /*@Override
    public boolean equals(Object obj) {
        if(this == null)//是否为空
            return false;
        if(this == obj)//地址相同
            return true;
        if(!(obj instanceof Person))//obj 不是 Person 类
            return false;
        Person per = (Person)obj;
        return (this.name.equals(per.name)) && this.age == per.age;
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
public class Test2 {
    public static void main(String[] args) {
        Person per1 = new Person("lisa", 10);
        Person per2 = new Person("lisa", 10);
        if(per1.equals(per2))
            System.out.println("true");
        else
            System.out.println("false");
    }
}
